<template>
    <el-dialog title="编辑老师" visible :show-close="false" class="wrap" size="tiny">
        <i class="el-icon-close close" @click="cancel"></i>
        <el-form label-width="100px" class="form">
            <el-form-item label="老师中文名">
                <el-input v-model="form.chinese" class="select-block"></el-input>
            </el-form-item>
            <el-form-item label="老师英文名">
                <el-input v-model="form.english" class="select-block"></el-input>
            </el-form-item>
            <el-form-item label="老师类型">
                <el-select v-model="form.type" placeholder="请选择..." class="select-block">
                    <el-option label="老师" value="ls"></el-option>
                    <el-option label="助教" value="zj"></el-option>
                    <el-option label="助教" value="xz"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="电话">
                <el-input v-model="form.phone" class="select-block"></el-input>
            </el-form-item>
            <el-form-item label="性别">
                <el-switch v-model="form.sex" on-color="#13ce66" off-color="#ff4949" on-value="男" off-value="女" on-text="男" off-text="女"></el-switch>
            </el-form-item>
            <el-form-item label="学校">
                <el-select v-model="form.school" placeholder="请选择..." class="select-block">
                    <el-option :label="v.mc" :value="v.id" v-for="v in schoolList"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="是否启用">
                <el-switch v-model="form.isqy" on-value="Y" off-value="N"></el-switch>
            </el-form-item>
        </el-form>
        <el-button type="info" class="submit" @click="submit">修改</el-button>
    </el-dialog>
</template>

<script type="text/javascript">
    export default {
        props: ['params'],
        data () {
            return {
                form: {
                    type: '',
                    isqy: '',
                    school: '',
                    chinese: '',
                    english: '',
                    phone: '',
                    sex: ''
                },
                type: '',
                schoolList: []
            }
        },
        created () {
            // console.log(this.params)
            var row = this.params.row;
            this.form = {
                type: row.emptype,
                isqy: row.isqy,
                school: row.xxid,
                chinese: row.zwm,
                english: row.ywm,
                phone: row.dh,
                sex: row.xb
            }
            this.getSchoolList();
        },
        methods: {
            submit () {
                this.$store.state.loading = true;
                if (!this.form.chinese) {
                    this.$message.warning('请填写老师中文名');
                    return;
                }else if(!this.form.type){
                    this.$message.warning('请选择老师类型');
                    return;
                }else if(!this.form.school){
                    this.$message.warning('请选择学校');
                    return;
                }
                this.axios.get( this.$store.state.api + 'emp/edit', {
                    params: {
                        id: this.params.row.id,
                        zwm: this.form.chinese,
                        ywm: this.form.english,
                        dh: this.form.phone,
                        xb: this.form.sex,
                        xxid: this.form.school,
                        isqy: this.form.isqy,
                        emptype: this.form.type,
                    }
                }).then( res => {
                    console.log({
                        id: this.params.row.id,
                        zwm: this.form.chinese,
                        ywm: this.form.english,
                        dh: this.form.phone,
                        xb: this.form.sex,
                        xxid: this.form.school,
                        isqy: this.form.isqy,
                        emptype: this.form.type,
                    })
                    console.log(res)
                    if (res.data.code == 1) {
                        this.$emit('close',{type:'edit',cancel:false});
                        this.$store.state.loading = false;
                    }else{
                        this.$emit('close',{type:'edit',cancel:false});
                        this.$store.state.loading = false;
                    }
                    
                }).catch( res => {
                    console.log(res)
                    this.$emit('close',{type:'edit',cancel:false});
                    this.$store.state.loading = false;
                })
            },
            getTime (val) {
                this.form.time = val;
            },
            cancel () {
                this.$emit('close',{type:'edit',cancel:true})
            },
            getSchoolList () {
                this.axios.get( this.$store.state.api + 'emp/xxlist')
                .then( res => {
                    console.log(res)
                    this.schoolList = res.data.data.list;
                }).catch( res => {
                    console.log(res)
                })
            }
        }
    }
</script>

<style lang="less" scoped>
    .wrap {
        text-align: center;
    }
    .form {
        // width: 300px;
        text-align: left;
    }
    .select-block {
        display: block;
    }
    .submit {
        width: 120px;
    }
</style>